package com.qj.daibei.controller;

import com.qj.daibei.pojo.District;
import com.qj.daibei.service.DistrictService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;

import java.util.List;

/**
 * author wml
 * Created on 2021/9/24 15:06
 */
@Controller
public class DistrictController {

    @Autowired
    private DistrictService districtService;

    /**
     * 查询所有的地区
     * @Author wml
     * @return 返回一个 JSON 格式的地区集合
     */
    @GetMapping("/ajaxGetDistrict")
    public ResponseEntity<List<District>> ajaxGetDistrict() {
        List<District> districtList = this.districtService.queryAllDistrict();
        return new ResponseEntity<List<District>>(districtList, HttpStatus.OK);
    }

    /**
     * 接收前端传来的城市 id，查询这个城市下的所有地区
     * @Author wml
     * @param cityId
     * @return 返回一个 JSON 格式的地区集合
     */
    @GetMapping("/ajaxGetDistrictByCityId")
    public ResponseEntity<List<District>> ajaxGetDistrictByCityId(String cityId) {
        List<District> districtList = this.districtService.queryDistrictByCityId(cityId);
        return new ResponseEntity<List<District>>(districtList, HttpStatus.OK);
    }
}
